﻿Imports Microsoft.WindowsMobile

Public Class Settings
    Public Function GetStatus() As String

        Dim PhoneOff = Microsoft.WindowsMobile.Status.SystemState.PhoneRadioOff

        Dim SignalSt As Integer
        Dim OperatorName As String

        If Not PhoneOff Then
            Try
                SignalSt = Microsoft.WindowsMobile.Status.SystemState.PhoneSignalStrength
                OperatorName = Microsoft.WindowsMobile.Status.SystemState.PhoneOperatorName
            Catch ex As Exception
                'Nothing to deal with, phone is warming up
                SignalSt = 0
                OperatorName = "Initializing ..."
            End Try
        Else
            SignalSt = 0
            OperatorName = "Phone is Off"
        End If
        Dim BlueToothOn = Microsoft.WindowsMobile.Status.SystemState.BluetoothStatePowerOn

        Dim BatteryLevel = Microsoft.WindowsMobile.Status.SystemState.PowerBatteryStrength.ToString & " - " & _
                           Microsoft.WindowsMobile.Status.SystemState.PowerBatteryState.ToString()

        Dim WifiOn = Microsoft.WindowsMobile.Status.SystemState.WiFiStatePowerOn

        Dim SoundLevel = OpenNETCF.Media.SystemSound.GetVolume

        If PhoneOff Then SignalSt = 0

        Dim jPattern = _
        "{{'signal':{0},'blueTooth':{1},'operatorName':'{2}','batteryLevel':'{3}','wifi':{4},'soundLevel':{5}}}"


        Return String.Format(jPattern, SignalSt, BlueToothOn.ToString.ToLower, OperatorName, BatteryLevel, WifiOn.ToString.ToLower, SoundLevel)
    End Function
End Class
